﻿using System;
using System.Collections.Generic;
using System.Text;
using Spring.Data.NHibernate;
using Spring.Data.NHibernate.Support;
using System.Collections;
using SpringNH.Model;



namespace SpringNH.Impl
{
   public  class ItemsDao : HibernateDaoSupport
    {
       public ItemsDao()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
       public bool SaveOrUpdate(Items Obj)
        {
            HibernateTemplate.SaveOrUpdate(Obj);
            return true;
        }
       public bool Save(Items Obj)
        {
            HibernateTemplate.Save(Obj);
            return true;
        }

       public bool DeleteObject(Items Obj)
        {
            HibernateTemplate.Delete(Obj);
            return true;
        }

       public bool UpdateObject(Items Obj)
        {
            HibernateTemplate.Update(Obj);
            return true;
        }

        public IList GetAllObjectsList()
        {
            return HibernateTemplate.LoadAll(typeof(Items));
        }

        public IList GetObjectsList(string Key, string Value)
        {
            if (Value != null)
            {
                string hql = " from Items where  " + Key + " = " + Value + "";
                return HibernateTemplate.Find(hql, new object[] {});
            }
            else
            {
                string hql = " from Items where  " + Key + " is null";
                return HibernateTemplate.Find(hql, new object[] {  });
            }
        }

        public Items Load(Object ItemTitle)
        {
            return (Items)HibernateTemplate.Load(typeof(Items),ItemTitle);
        }
    }
}
